package com.whcity.tkgenerator.generator.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 分页查询参数模型
 *
 */
@ApiModel
public class PageRO implements Serializable {

    private static final long serialVersionUID = -7929173427257842819L;

    /**
     * 当前页
     */
    @ApiModelProperty(value = "当前页", example = "1")
    private int currentPage = 1;
    /**
     * 每页条数
     */
    @ApiModelProperty(value = "每页条数", example = "15")
    private int pageSize = 15;
    /**
     * mysql数据库查询条件
     */
    @ApiModelProperty()
    private int limitFrom;
    /**
     * 查询起始时间
     */
    @ApiModelProperty(hidden = true)
    private Date createdFrom;
    /**
     * 查询结束时间
     */
    @ApiModelProperty(hidden = true)
    private Date createdTo;

    /**
     * 请求参数
     */
    @ApiModelProperty(hidden = true)
    private Map<String, Object> params;


    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage <= 0 ? 1 : currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        if (pageSize > 0) {
            this.pageSize = pageSize;
        }
    }

    public int getLimitFrom() {
        limitFrom = (currentPage - 1) * pageSize;
        return limitFrom;
    }

    public Date getCreatedFrom() {
        return createdFrom;
    }

    public void setCreatedFrom(Date createdFrom) {
        this.createdFrom = createdFrom;
    }

    public Date getCreatedTo() {
        return createdTo;
    }

    public void setCreatedTo(Date createdTo) {
        this.createdTo = createdTo;
    }


    public Map<String, Object> getParams() {
        if (params == null) {
            params = new HashMap<>();
        }
        return params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }
}
